package com.tz.service;

import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.java_websocket.client.WebSocketClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RocketMQMessageListener(topic = "my-topic", consumerGroup = "my-consumer-group")
public class ConsumerService implements RocketMQListener<String> {
    private static final Logger log = LoggerFactory.getLogger(ConsumerService.class);

    @Autowired
    private WebSocketClient webSocketClient;

    @Override
    public void onMessage(String message) {

        JSONObject jsonObject = JSONObject.parseObject(message);

        webSocketClient.send(message);
        //System.out.println("收到消息: " + message);
    }
}
